package kmu.lwl.controller;

import kmu.lwl.entiy.Course;
import kmu.lwl.entiy.Connection;
import kmu.lwl.entiy.Login;
import kmu.lwl.imp.CourseDao;
import kmu.lwl.imp.impl.CourseDaoimpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import java.util.Map;

public class PersonalCourseController extends ActionSupport {

   private Course course ;

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    private Connection connection;

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public String selectCourse() throws Exception{
       Map session = (Map) ActionContext.getContext().getSession();
       Login user = (Login) session.get("user");
       CourseDao courseDao = new CourseDaoimpl();
       List studentAllCourse = courseDao.getStudentAllCourse(user.getLoginName());
       Map request = (Map) ActionContext.getContext().get("request");
       request.put("studentAllCourse",studentAllCourse);
       return SUCCESS;
  }
  public String chosen() throws  Exception{
      Map session = (Map) ActionContext.getContext().getSession();
      Login user = (Login) session.get("user");
      connection.setStudentId(user.getLoginName());
      CourseDao courseDao = new CourseDaoimpl();
      courseDao.chosenCourse(connection);
      return SUCCESS;
  }
}

